package com.example.systemwork.service;

import com.example.systemwork.common.service.LogicService;
import com.example.systemwork.dao.BusinessDao;
import com.example.systemwork.dao.ItemDao;
import com.example.systemwork.dao.ShopDao;
import com.example.systemwork.dao.ShopItemDao;
import com.example.systemwork.entity.*;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class BusinessService extends LogicService<BusinessDao, Business,Long> {
    public BusinessService(@Autowired BusinessDao dao) {
        super(dao);
    }
    @Resource
    private ShopDao shopDao;
    @Resource
    private ShopItemDao shopItemDao;
    @Resource
    private ItemDao itemDao;
    public Shop createShop(Long bus_id,String shopName){
        Business business=getDAO().getReferenceById(bus_id);
        Shop shop=business.addShop(shopName);
        getDAO().save(business);
        return shop;
    }

    public ShopItem shelfGoods(Long shopId, Long itemId){
        Shop shop=shopDao.getReferenceById(shopId);
        Item item=itemDao.getReferenceById(itemId);
        ShopItem shopItem=shop.PutOnItem(item);
        if(shopItem!=null)shopDao.save(shop);
        return null;
    }

    //是商家新建item 还是建立shopItem
    public Item newItem (Long bus_id,String itemName,Double price){
        Business business=getDAO().getReferenceById(bus_id);
        Item item=new Item();
        item.setItemName(itemName);
        item.setPrice(price);
        item.setBusiness(business);
        itemDao.save(item);
        return item;
    }

}
